//
//  ChangeLocationViewCtrler.m
//  MIDI
//
//  Created by 千行时线 on 15/9/15.
//  Copyright (c) 2015年 QXSX. All rights reserved.
//

#import "ChangeLocationViewCtrler.h"
#import "AppConfig.h"

@interface ChangeLocationViewCtrler ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *cityNameUITextField;
@property (weak, nonatomic) IBOutlet UIPickerView *captainUIPickerView;
@property (weak, nonatomic) IBOutlet UIPickerView *cityUIPickerView;

@property (assign,nonatomic) NSInteger captainindex;
@property (assign,nonatomic) NSInteger cityindex;

@end

@implementation ChangeLocationViewCtrler

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self configNavigationItem];
    
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return 10;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
    return [UIScreen mainScreen].bounds.size.width /2;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 35;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (pickerView == self.captainUIPickerView)
    {
        self.captainindex = row;
    }
    else
    {
        self.cityindex = row;
    }
    [self.cityNameUITextField setText: [NSString stringWithFormat:@"%ld:%ld",self.captainindex,self.cityindex]];
    
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];
        
        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont fontWithName:@"Hiragino Sans GB" size:18]];
        pickerLabel.textColor = [UIColor blackColor];
        if (pickerView == self.captainUIPickerView)
        {
            [pickerLabel setTextAlignment:NSTextAlignmentRight];
            [pickerLabel setText:@"hello\t\t"];
        }
        else
        {
             [pickerLabel setTextAlignment:NSTextAlignmentLeft];
            [pickerLabel setText:@"\t\tworld"];
        }
        
        
    }
    return pickerLabel;
}

-(void) configNavigationItem
{
    [self.tabBarController configNavigationBarTintColor:UIColorRGBA(0, 0, 0, 1)];
    [self.navigationController.navigationBar setBarTintColor:MIDIColorOfNavigationBar];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationItem.title = @"所在地";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],UITextAttributeFont,nil]];
    
    [self configNavigationBackAction:^{
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

@end
